import 'dart:async';
import 'dart:io';

import 'package:app/page/index_page.dart';
import 'package:app/routes.dart';
import 'package:app/utils/shared_preferences_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jpf_core/config/cupertino_localizations_delegate.dart';
import 'package:flutter_jpf_debug/log.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'generated/app_config.dart';


void main() {

  //其他类型异常
  runZoned(
        () => realRunApp(),
    onError: (dynamic ex, StackTrace stack) {
      print("$ex  $stack");
    },
  );
}



void realRunApp() async {
  Log.dealLevel = LogLevel.debug;
  AppConfig.setAppConfig();

  WidgetsFlutterBinding.ensureInitialized();
  bool success = await SharedPreferencesUtil.getInstance();
  print("init-" + success.toString());
  runApp(MyAppPage());
}

class MyAppPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState(){
    // TODO: implement getPageState
    return _MyAppPageState();
  }
}

class _MyAppPageState extends State<MyAppPage>{
  Widget mainWidget;


  @override
  void initState() {
    //UIPage
    mainWidget = IndexPage();
  }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        localizationsDelegates: [
          CupertinoLocalizationsDelegate(),
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: [
          const Locale('zh', 'CN'),
          const Locale('en', 'US'),
        ],
        title: "",
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
          buttonTheme: new ButtonThemeData(
              minWidth: 0,
              height: 0,
              padding: EdgeInsets.all(0),
              buttonColor: Colors.transparent),
        ),
        home: mainWidget,
        routes: Routes.all);
  }
}

